package com.baichang.taoshunda.controller.mobile;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ${wushenglu} on 17/09/04.
 */
@Controller
@RequestMapping(ControllerConstants.SCORE)
public class ScoreMCtronller extends BaseMobileController {
    @Autowired
    private ScoreService scoreService;

    @RequestMapping("/addScore")
    public void addScore(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                int typeId = getInt(json, "typeId", 1);
                int userId = getInt(json, "userId", 0);
                return scoreService.addScoreByType(typeId,userId);
            }
        });
    }
    @RequestMapping("/getStateAndScore")
    public  void getStateAndScore(HttpServletResponse response,HttpServletRequest request){
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                int userId = getInt(json, "userId", 0);
                return scoreService.getStateAndScore(userId);
            }
        });
    }
}
